package com.lyz.jingjie;

/**
 * @ClassName RegexDemo1
 * @Description 校验qq号码 6-20必须全部数字
 * @Author 2214361854
 * @Date 2022/2/20 12:56
 * @Version 1.0
 */
public class RegexDemo1 {
    public static void main(String[] args) {
        String qq1 = "1839347123";
        String qq2 = "18393a47a123";
        System.out.println(checkQQ(qq1));
        System.out.println(checkQQ(qq2));

        System.out.println(checkQQ2(qq1));
        System.out.println(checkQQ2(qq2));
    }

    /**
     * 正则表达式写法
     * @param qq
     * @return
     */
    private static boolean checkQQ2(String qq) {
        return qq != null && qq.matches("\\d{6,20}");
    }

    /**
     * 方法写法
     * @param qq
     * @return
     */
    private static boolean checkQQ(String qq) {
        if (qq == null||qq.length()<6||qq.length()>20) {
            return false;
        }
        for (int i = 0; i < qq.length(); i++) {
            char ch = qq.charAt(i);
            if (ch < '0'|| ch > '9') {
                return false;
            }
        }
        return true;
    }

}
